<?php

define("TEMPLATE_FILE", "derivedTemp.php");
define("DEF_FILE", "def.php");
define("OUTPUT_DIR", "../");

$content=file_get_contents(TEMPLATE_FILE);
$definitions=require(DEF_FILE);
$IDs='';
foreach ($definitions as $def)
{
	file_put_contents(OUTPUT_DIR."Location_${def['id']}.php", 
		strtr($content, 
			array(
				'{ID}'=>$def['id'],
				'{Name}'=>$def['name'],
				'{Type}'=>$def['type'],
				'{Fightable}'=>($def['type']==0 ? 'false':'true'),
				'{Enemies}'=>$def['enemies'],
                '{View}'=>(isset($def['view'])? $def['view'] : "locations/${def['id']}"),
			)
		)
	);
	$IDs.="${def['id']}=>1,";
}

$content=file_get_contents('baseTemp.php');
file_put_contents(OUTPUT_DIR."Location.php", 
	strtr($content, 
		array(
			'{IDs}'=>$IDs,
		)
	)
);

?>
